/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = __conn_key2.c                                     */
/*  NOTE      =                                                    */
/*  DATE      = 2016/04/12 by jikw                                 */
/*******************************************************************/

#include <CUnit/Basic.h>
#include <stdlib.h>

#include "frcomm.h"
#include "frmem.h"
#include "conntrack.h"
#include "frct_comm.h"
#include "frexp_comm.h"
#include "frstat_port.h"

extern int __conn_key(u_int ui_src_ip, u_int ui_dst_ip, u_short us_dst_port, char *p_key, unsigned int ui_key_size);

static int __suite_init(void)
{

	return 0;
}

static int __suite_cleanup(void)
{

	return 0;
}

static void case1(void)
{
    int i_ret = 0;
    u_int ui_sip = iptools_parse_ipaddr("192.168.1.1");
    u_int ui_dip = iptools_parse_ipaddr("192.168.0.1");
    u_short us_dport = 80;
    
    i_ret = __conn_key(ui_sip, ui_dip, us_dport, NULL, 0);

    CU_ASSERT_EQUAL(i_ret, 0);

    return;
}

static void case2(void)
{
    int i_ret = 0;
    char arr_key[10];
    u_int ui_sip = iptools_parse_ipaddr("192.168.1.1");
    u_int ui_dip = iptools_parse_ipaddr("192.168.0.1");
    u_short us_dport = 80;
    
    i_ret = __conn_key(ui_sip, ui_dip, us_dport, arr_key, sizeof(arr_key));

    CU_ASSERT_EQUAL(i_ret, 0);

    return;
}

static void case3(void)
{
    int i_ret = 0;
    char arr_key[20];
    u_int ui_sip = iptools_parse_ipaddr("192.168.1.1");
    u_int ui_dip = iptools_parse_ipaddr("192.168.0.1");
    u_short us_dport = 80;
    
    i_ret = __conn_key(ui_sip, ui_dip, us_dport, arr_key, sizeof(arr_key));

    CU_ASSERT_EQUAL(i_ret, 10);

    return;
}

int add_suite__conn_key2(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite("framework __conn_key2()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    if (CU_add_test(pSuite, "case1", case1) == NULL ||
        CU_add_test(pSuite, "case2", case2) == NULL ||
        CU_add_test(pSuite, "case3", case3) == NULL)
        return FR_FAIL;

    return FR_SUCC;
}
